﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace MovieExplorer
{
    public partial class ChooseImageDlg : Form
    {
        public ChooseImageDlg()
        {
            InitializeComponent();
        }

        public List<string> Images { get; set; }

        private void ChooseImageDlg_VisibleChanged(object sender, EventArgs e)
        {
            if (Visible)
            {
                imageList.Images.Clear();
                listView.View = View.LargeIcon;
                imageList.ImageSize = new Size(100, 100);

                List<string> sizes = new List<string>();
                foreach (string image in Images)
                {
                    WebRequest reqI = WebRequest.Create(image);
                    try
                    {
                        WebResponse responseI = reqI.GetResponse();
                        Stream streamI = responseI.GetResponseStream();

                        Image img = Image.FromStream(streamI);
                        sizes.Add(string.Format("{0}x{1}", img.Size.Width, img.Size.Height));
                        imageList.Images.Add(img);
                    }
                    catch { }
                }

                listView.LargeImageList = imageList;

                for (int j = 0; j < imageList.Images.Count; j++)
                {
                    ListViewItem lstItem = new ListViewItem();
                    lstItem.Text = sizes[j];
                    lstItem.ImageIndex = j;
                    listView.Items.Add(lstItem);
                }
            }
        }
    }
}